//
//  ViewController.m
//  DrawImage
//
//  Created by zero on 2017/6/1.
//  Copyright © 2017年 zero. All rights reserved.
//

#import "ViewController.h"
#import "UIImage+Helper.h"
#import <Photos/Photos.h>

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UIImageView* imv = [[UIImageView alloc]initWithFrame:self.view.bounds];
    
    UIImage* image = [UIImage drawWithImage:[UIImage imageNamed:@"IMG_0139.JPG"] Title:@"我在一个人无聊的敲代码，敲代码，敲代码，敲代码，敲代码，敲代码，敲代码，敲代码，敲代码，敲代码，敲代码，敲代码，敲代码，敲代码，敲代码，敲代码"];
    imv.image = image;
    imv.contentMode = UIViewContentModeScaleAspectFit;
    
    [self.view addSubview:imv];
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), (__bridge void *)self);
//    [self saveToSystemPhoto];
}

- (void)saveImage{
    [PHPhotoLibrary sharedPhotoLibrary];
}
- (void)saveToSystemPhoto{
    UIImage* image = [UIImage drawScreenshot:self.view];
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), (__bridge void *)self);
}

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
    NSLog(@"image = %@, error = %@, contextInfo = %@", image, error, contextInfo);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
